#include <iostream>
#include "demo04.cpp"
#include "fiber.h"
#include "marco.h"
#include "util.h"
#include "demo08.h"

Logger::ptr lg = createLogger();

void func(){
    SYLAR_LOG_INFO(lg)<<"func start";
    Fiber::YieldToHold();
    SYLAR_LOG_INFO(lg)<<"func end";
    Fiber::YieldToHold();
}

void test_fiber(){
    SYLAR_LOG_INFO(lg)<<"main start -1";
    {
        Fiber::GetThis();
        SYLAR_LOG_INFO(lg)<<"main start";
        Fiber::ptr fiber(new Fiber(func));
        fiber->swapIn();
        SYLAR_LOG_INFO(lg)<<"main after swapIn";
        fiber->swapIn();
        SYLAR_LOG_INFO(lg)<<"main end";
        fiber->swapIn();
    }
    SYLAR_LOG_INFO(lg)<<"main end2";
}

int main(int argc, char** argv){
    Thread::SetName("main");

    std::vector<Thread::ptr> thrs;
    for(int i = 0; i < 3; ++i) {
        thrs.push_back(Thread::ptr(
                    new Thread(&test_fiber, "name_" + std::to_string(i))));
    }
    for(auto i : thrs) {
        i->join();
    }


    return 0;
}